//  DetailIncomeTBV.m
//  XJMTechnician
//  Created by Mr.hu on 2017/10/17.
//  Copyright © 2017年 Mr.hu. All rights reserved.

#import "DetailIncomeTBV.h"
#import "IntegerDetailTBVCell.h"
@interface DetailIncomeTBV ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *IncomeDetailTable;

@property (nonatomic,strong)  NSMutableArray * incomeDetail;
@property (nonatomic,strong)  UIView * backview;
@property (nonatomic) NSInteger page;

@end

@implementation DetailIncomeTBV

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBtn:[UIImage imageNamed:@"fanhui"] Action:@selector(backToPrevious)];
    self.title = @"账户明细";
    [self MineIntegerDetailTableView];
    self.incomeDetail = [NSMutableArray array];
    
    self.page=1;
    self.IncomeDetailTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self income_detailRequest:self.page];
        [self.IncomeDetailTable.mj_header endRefreshing];
    }];
    
    self.IncomeDetailTable.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self income_detailRequestPulldown:++self.page];
        [self.IncomeDetailTable.mj_footer endRefreshing];
    }];
    self.IncomeDetailTable.mj_footer.automaticallyHidden = YES;
    
    [self income_detailRequest:self.page];
    
    self.backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    self.backview.backgroundColor = RGBA(243, 243, 243, 1);
    [self.view addSubview:self.backview];
    UIImageView * topimageview = [[UIImageView alloc]init];
    [topimageview setImage:[UIImage imageNamed:@"no_colle"]];
    [self.backview addSubview:topimageview];
    [topimageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(150);
        make.size.mas_equalTo(CGSizeMake(120, 120));
        make.centerX.equalTo(self.view);
    }];
    
    UILabel * sizelabe = [[UILabel alloc]init];
    sizelabe.text = @"暂无明细";
    sizelabe.font = [UIFont systemFontOfSize:16];
    sizelabe.textColor = [UIColor grayColor];
    sizelabe.textAlignment = NSTextAlignmentCenter;
    [self.backview addSubview:sizelabe];
    [sizelabe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topimageview.mas_bottom).offset(10);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
    
}

- (void)income_detailRequest:(NSInteger)page{
    
    [XJHttpClass  Techerincome_detailtoken:[XJToolClass getToken] page:[NSString stringWithFormat:@"%ld",(long)page] andFinishblock:^(id response, NSString *errStr) {
        
        if (errStr) {
            self.backview.hidden = NO;
        }else{
            NSDictionary * dictdata = response[@"data"];
            if ([dictdata isKindOfClass:[NSDictionary class]]) {
                
                [self.incomeDetail removeAllObjects];
                self.incomeDetail = dictdata[@"list"];
                [self.IncomeDetailTable reloadData];
                self.backview.hidden = YES;
            }
        }
    }];
}

- (void)income_detailRequestPulldown:(NSInteger)page{
    
    [XJHttpClass  Techerincome_detailtoken:[XJToolClass getToken] page:[NSString stringWithFormat:@"%ld",(long)page] andFinishblock:^(id response, NSString *errStr) {
        
        if (errStr) {
//            [XJToolClass tipAnimationWith:errStr];
            [self.IncomeDetailTable.mj_footer endRefreshingWithNoMoreData];
        }else{
            
            NSDictionary * dictdata = response[@"data"];
            if ([dictdata isKindOfClass:[NSDictionary class]]) {
                
                [self.incomeDetail addObject: dictdata[@"list"]];
                [self.IncomeDetailTable reloadData];
                self.backview.hidden = YES;
            }
        }
    }];
}

- (void)MineIntegerDetailTableView{
    
    self.IncomeDetailTable.delegate = self;
    self.IncomeDetailTable.dataSource = self;
    self.IncomeDetailTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.IncomeDetailTable registerNib:[UINib nibWithNibName:@"IntegerDetailTBVCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"IntegerDetailTBVCell"];
}

#pragma mark - TableViewDatasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.incomeDetail isKindOfClass:[NSMutableArray class]]?self.incomeDetail.count:0;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    IntegerDetailTBVCell * friend=[tableView dequeueReusableCellWithIdentifier:@"IntegerDetailTBVCell" forIndexPath:indexPath];
    [friend setData:self.incomeDetail[indexPath.row]];
    
    return friend;
}

#pragma mark TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当手指离开某行时，就让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
